package com.ccq.controller;


import java.io.UnsupportedEncodingException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ccq.MailConfig;
import com.ccq.domain.Result;
import com.ccq.util.ResultUtil;

@RestController
public class SendSimplMailController {
	@Autowired
	private	JavaMailSender javaMailSender;
	@Autowired
	private MailConfig mailConfig;
	@SuppressWarnings("unchecked")
	@GetMapping("sendMail")
	public <T> Result<T> sendSimplMail() throws UnsupportedEncodingException{
		SimpleMailMessage s=new SimpleMailMessage();
		s.setFrom(mailConfig.sendFrom);
		s.setTo(mailConfig.sendTo);
		s.setSubject(mailConfig.sentSubject);
		s.setText(mailConfig.sentText);
		javaMailSender.send(s);
		return (Result<T>) ResultUtil.success(mailConfig.sentSubject);
	}
}
